import { createRouter, RouteRecordRaw, createWebHashHistory } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: '/home',
    component: () => import(/* webpackChunkName: "layout" */ '../layout/index.vue'),
    children: [
      {
        path: '/home',
        name: 'Home',
        component: () => import(/* webpackChunkName: "home" */ '../views/Home.vue')
      },
      {
        path: '/about',
        name: 'About',
        component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
      },
      {
        path: '/troisjs',
        name: 'TroisJS',
        component: () => import(/* webpackChunkName: "troisjs" */ '../views/TroisJS.vue')
      },
      {
        path: '/electron',
        name: 'Electron',
        component: () => import(/* webpackChunkName: "electron" */ '../views/Electron.vue')
      }
    ]
  },
  {
    path: '/webgl',
    name: 'WebGL',
    component: () => import(/* webpackChunkName: "webgl" */ '../views/WebGL.vue')
  },
  {
    path: '/example',
    name: 'Example',
    component: () => import(/* webpackChunkName: "example" */ '../views/Example.vue')
  },
  {
    path: '/global',
    name: 'Global',
    component: () => import(/* webpackChunkName: "global" */ '../views/Global.vue')
  },
  {
    path: '/virtual',
    name: 'Virtual',
    component: () => import(/* webpackChunkName: "virtual" */ '../views/Virtual.vue')
  }
]

// One thing to note is that electron does not support history mode
// https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/commonIssues.html
const router = createRouter({
  routes,
  history: createWebHashHistory(process.env.BASE_URL)
})

router.beforeEach((to, from, next) => {
  next()
  console.log('to URL:', to.fullPath)
})

export default router
